package com.cn.wanxi.service.impl;

import com.alibaba.druid.sql.dialect.postgresql.visitor.PGEvalVisitor;
import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.dao.impl.ProductImpl;
import com.cn.wanxi.dto.CommonModelDto;
import com.cn.wanxi.dto.ProductModelDto;
import com.cn.wanxi.model.PageModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.IProductService;

import java.util.List;

/**
 * 服务层
 */
public class ProductServiceImpl implements IProductService {
    @Override
    public List<ProductModel> getFindAll() {
        ProductDao productDao = new ProductImpl();
        return productDao.getFindAll();
    }

    @Override
    public void add(ProductModel productModel) {
        ProductDao productDao = new ProductImpl();
        productDao.add(productModel);
    }

    /**
     * 根据菜系ID查询当前所有产品
     *
     * @param productModel
     * @return
     */
    @Override
    public ResultModel findByCookStyleId(ProductModel productModel) {
        ProductDao productDao = new ProductImpl();
        ResultModel resultModel = new ResultModel();
        resultModel.setCount(productDao.count(productModel.getCookstyleid()));

        ProductModelDto productModelDto = new ProductModelDto();
        productModelDto.setCommonModelDto(new CommonServiceImpl().getCommonModelDto());
        productModelDto.setProductModelList(productDao.findByCookStyleId(productModel));
        resultModel.setObject(productModelDto);
        return resultModel;
    }
}
